//
//  MyUtil.m
//  everyoneBroadcast
//
//  Created by Geek on 15/6/2.
//  Copyright (c) 2015年 Geek. All rights reserved.
//

#import "MyUtil.h"

@implementation MyUtil

+ (UIButton *)createBtnFrame:(CGRect)frame image:(NSString *)imageName selectedImage:(NSString *)selectedImageName target:(id)target action:(SEL)action tag:(CGFloat)tag
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    btn.tag = tag;
    if (imageName) {
        [btn setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    }
    
    if (selectedImageName) {
        [btn setBackgroundImage:[UIImage imageNamed:selectedImageName] forState:UIControlStateSelected];
    }
    
    if (target && action) {
        [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    }
    
    return btn;
    
}

+ (UILabel *)createLabelFrame:(CGRect)frame title:(NSString *)title textAlignment:(NSTextAlignment)textAlignment
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    if (title) {
        label.text = title;
    }
    
    if (textAlignment) {
        label.textAlignment = textAlignment;
    }
    
    return label;
    
}

//创建UIImageView的方法 ----
+ (UIImageView *)createImageViewFrame:(CGRect)frame imageName:(NSString *)imageName
{
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:frame];
    imageview.image = [UIImage imageNamed:imageName];
    
    //开启用户交互
    imageview.userInteractionEnabled = YES;
    
    return imageview;
    
}
//正则判断
- (BOOL) regexFlagWith:(NSString *)regex withParameter:(NSString *)parameter{
    
    NSPredicate *pass = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    
    return [pass evaluateWithObject:parameter];
    
}


@end
